package avicit.bdp.dms.approval.rest;

import avicit.bdp.common.dto.approval.ApprovalDTO;
import avicit.bdp.dms.approval.dto.ApprovalHistoryDTO;
import avicit.bdp.dms.approval.service.ApprovalService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-06-20
 * @类说明：ApprovalRest
 * @修改记录：
 * @注意事项：
 * @主要功能：审批中心Rest接口
 */
@RestController
@Api(tags = "approval", description = "审批中心Rest接口")
@RequestMapping("/api/bdp/dms/approval")
public class ApprovalRest {
    @Autowired
    ApprovalService approvalService;

    /**
     * 批量申请
     * @param applyList
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "申请/批量申请")
    public ResponseMsg<Boolean> addApproval(@RequestBody List<ApprovalDTO> applyList) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.addApproval(applyList));

        return responseMsg;
    }

    /**
     * 批量处理申请
     * @param applyList
     * @return
     */
    @PostMapping("/process")
    @ApiOperation(value = "处理申请")
    public ResponseMsg<Boolean> processApproval(@RequestBody List<ApprovalDTO> applyList) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.processApproval(applyList));

        return responseMsg;
    }

    /**
     * 批量撤回申请
     * @param applyList
     * @return
     */
    @PostMapping("/revoke")
    @ApiOperation(value = "撤回申请")
    public ResponseMsg<Boolean> revokeApproval(@RequestBody List<ApprovalDTO> applyList) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.revokeApproval(applyList));

        return responseMsg;
    }

    /**
     * 删除/批量删除审批，多个id使用英文逗号隔开
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除/批量删除审批，多个id使用英文逗号隔开")
    public ResponseMsg<Integer> deleteApproval(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.deleteApproval(id));

        return responseMsg;
    }

    /**
     * 申请/批量更新
     * @param applyList
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "申请/批量更新")
    public ResponseMsg<Boolean> updateApproval(@RequestBody List<ApprovalDTO> applyList) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.updateApproval(applyList));

        return responseMsg;
    }

    /**
     * 查询申请详情
     * @param id 申请ID
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查询申请详情")
    public ResponseMsg<ApprovalDTO> getApprovalDetail(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<ApprovalDTO> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.getApprovalDetail(id));

        return responseMsg;
    }

    /**
     * 分页查询我的审批列表
     * @param type
     * @param state
     * @param startTime
     * @param endTime
     * @param keyWords
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/queryApprovalList")
    @ApiOperation(value = "分页查询我的审批列表")
    public ResponseMsg<QueryRespBean<ApprovalDTO>> queryApprovalList(
            @ApiParam(value = "申请类型，0：标准发布、1：质量发布、2：元数据发布", name = "type") @RequestParam Integer type,
            @ApiParam(value = "状态，0:待审批、1:通过、2:已驳回、3:已撤回", name = "state") @RequestParam(required = false, defaultValue = "-1") Integer state,
            @ApiParam(value = "开始时间", name = "startTime") @RequestParam(required = false)  String startTime,
            @ApiParam(value = "结束时间", name = "endTime") @RequestParam(required = false) String endTime,
            @ApiParam(value = "关键字", name = "keyWords") @RequestParam(required = false) String keyWords,
            @ApiParam(value = "当前页", name = "pageNo") @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @ApiParam(value = "每页大小", name = "pageSize") @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<ApprovalDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.queryApprovalList(type, state, startTime, endTime, keyWords, pageNo,pageSize));

        return responseMsg;
    }

    /**
     * 分页查询我的申请列表
     * @param type
     * @param state
     * @param startTime
     * @param endTime
     * @param keyWords
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/queryApplyList")
    @ApiOperation(value = "分页查询我的申请列表")
    public ResponseMsg<QueryRespBean<ApprovalDTO>> queryApplyList(
            @ApiParam(value = "申请类型，0：标准发布、1：质量发布、2：元数据发布", name = "type") @RequestParam Integer type,
            @ApiParam(value = "状态，0:待审批、1:通过、2:已驳回、3:已撤回", name = "state") @RequestParam(required = false, defaultValue = "-1") Integer state,
            @ApiParam(value = "开始时间", name = "startTime") @RequestParam(required = false)  String startTime,
            @ApiParam(value = "结束时间", name = "endTime") @RequestParam(required = false) String endTime,
            @ApiParam(value = "关键字", name = "keyWords") @RequestParam(required = false) String keyWords,
            @ApiParam(value = "当前页", name = "pageNo") @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @ApiParam(value = "每页大小", name = "pageSize") @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<ApprovalDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.queryApplyList(type, state, startTime, endTime, keyWords, pageNo,pageSize));

        return responseMsg;
    }

    /**
     * 查询审批进度
     * @param id 工单ID
     * @return
     */
    @GetMapping("/progress")
    @ApiOperation(value = "查询审批进度")
    public ResponseMsg<List<ApprovalHistoryDTO>> getApprovalProgress(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<List<ApprovalHistoryDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.approvalService.getApprovalProgress(id));

        return responseMsg;
    }
}
